﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using KXmlUIControl;

namespace FormPageConfigs.ChildPages
{
    public partial class PageConfigWorkflow : PageConfigBase
    {
        public PageConfigWorkflow()
        {
            InitializeComponent();
        }

        public PageConfigWorkflow(XmlModuleObject xmlObj)
        {
            ModuleObj = xmlObj;
            InitializeComponent();
        }

        private string XmlConfigFile = "";

        private XmlModuleObject ModuleObj = null;

        private XmlConfigModule ModuleConfig = null;

        private List<XmlPageObject> listConfigPages = new List<XmlPageObject>();
 
        public override bool LoadConfig()
        {
            string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
            directory = directory.Substring(6);
            DirectoryInfo dir = new DirectoryInfo(directory);
            directory = dir.Parent.FullName;
            XmlConfigFile = string.Format(@"{0}\Config\{1}.xml", directory, ModuleObj.Name);
            ModuleConfig = new XmlConfigModule(XmlConfigFile);
            if (ModuleConfig.OnReading())
            {
                listConfigPages = ModuleConfig.ListPages;
            }
            return true;
        }

        public override bool InitCtrls()
        {
            checkedListBox1.Items.Clear();
            int index = 0;
            for (int i = 0; i < listConfigPages.Count; i++)
            {
                XmlPageObject config = listConfigPages[i];
                index = checkedListBox1.Items.Add(config, config.Enable);
                checkedListBox1.SetItemCheckState(index, CheckState.Indeterminate);           
            }
            return true;
        }

        private void buttonUp_Click(object sender, EventArgs e)
        {
            
        }

        private void buttonDown_Click(object sender, EventArgs e)
        {

        }

        private void checkBoxSimpleMode_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void checkBoxSelectAll_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < checkedListBox1.Items.Count; i++)
            {
                checkedListBox1.SetItemChecked(i, true);
            }
        }

        public override bool UpdateData()
        {
            return true;
        }

        private void PageConfigWorkflow_Load(object sender, EventArgs e)
        {
            InitCtrls();
        }
    }
}
